/**通用计算**/
function calculate() {
    try {
        var province = ($("#province").length > 0) ? $("#province").val() : '';
        var city = ($("#city").length > 0) ? $("#city").val() : '';
        var mianji = ($("#mianji").length > 0) ? ($("#mianji").val() != '面积' ? $("#mianji").val() : '') : '';
        var phone = ($("#phone").length > 0) ? $("#phone").val() : '';
        var position = ($("#c-position").length > 0) ? $("#c-position").val() : '';
        var type = ($("#c-type").length > 0) ? $("#c-type").val() : '';
    } catch (e) {
    }
    $.ajax({
        type: "POST",
        url: "?controller=ajax/baoming&controllerAction=save",
        data: "type=" + type + "&phone=" + phone + "&province=" + province + "&city=" + city + "&mianji=" + mianji + "&position=" + position,
        dataType: "json",
        beforeSend: function () {
            var reg1 = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
            if ((!mianji && $("#mianji").length > 0) || mianji == '请填写房屋面积') {
                $("#mianji").focus();
                layer.msg('请填写房屋面积');
                return false;
            }
            else if (!reg1.test(phone) || phone == '请填写您的联系电话') {
                $("#phone").focus();
                layer.msg('请填写您的联系电话');
                return false;
            }
            else if ((!province && $("#province").length > 0) || province == '请选择省/市') {
                $("#province").focus();
                layer.msg('请选择省/市');
                return false;
            } else if ((!city && $("#city").length > 0) || city == '请选择市/地区') {
                $("#city").focus();
                layer.msg('请选择市/地区');
                return false;
            }
            var total = Math.floor($('#mianji').val() / 0.75 * 420),
                wsVal = Math.floor(total * 0.3400),
                ktVal = Math.floor(total * 0.3196),
                cfVal = Math.floor(total * 0.1121),
                wstVal = Math.floor(total * 0.1174),
                ytVal = Math.floor(total * 0.0359),
                qtVal = Math.floor(total * 0.0750),
                totalVal = wsVal + ktVal + cfVal + wstVal + ytVal + qtVal;
            $('#totalVal').html(totalVal);
            $('#wsVal').html(wsVal);
            $('#ktVal').html(ktVal);
            $('#cfVal').html(cfVal);
            $('#wstVal').html(wstVal);
            $('#ytVal').html(ytVal);
            $('#qtVal').html(qtVal);
        },
        success: function (result) {
            if (result.code == 1) {
                $('.cal-tip').show();
                $("form").each(function () {
                    this.reset();
                });
            }
            return false;
        }
    })
};


function calMaterial() {
	//alert('calMaterial!');
    try {
        var province = ($("#province").length > 0) ? $("#province").val() : '';
        var city = ($("#city").length > 0) ? $("#city").val() : '';
        var mianji = ($("#mianji").length > 0) ? ($("#mianji").val() != '面积' ? $("#mianji").val() : '') : '';
        var phone = ($("#phone").length > 0) ? $("#phone").val() : '';
        var position = ($("#c-position").length > 0) ? $("#c-position").val() : '';
        var type = ($("#c-type").length > 0) ? $("#c-type").val() : '';
        var landing_page = ($("#landing_page").length > 0) ? $("#landing_page").val() : '';
    } catch (e) {
    }
    $.ajax({
        type: "POST",
        url: "?controller=ajax/baoming&controllerAction=save",
        data: {
            "type": type,
            "phone": phone,
            "province": province,
            "city": city,
            "mianji": mianji,
            "position": position,
            "landing_page": landing_page
        },
        dataType: "json",
        beforeSend: function () {
            var reg1 = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
            if ((!province && $("#province").length > 0) || province == '请选择省/市') {
                $("#province").focus();
                layer.msg('请选择省/市');
                return false;
            } else if ((!city && $("#city").length > 0) || city == '请选择市/地区') {
                $("#city").focus();
                layer.msg('请选择市/地区');
                return false;
            } else if ((!mianji && $("#mianji").length > 0) || mianji == '请填写房屋面积') {
                $("#mianji").focus();
                layer.msg('请填写房屋面积');
                return false;
            }
            else if (!reg1.test(phone) || phone == '请填写您的联系电话') {
                $("#phone").focus();
                layer.msg('请填写您的联系电话');
                return false;
            }

            var total = Math.floor($('#mianji').val() / 0.75 * 420),
                labour = Math.floor(total * 0.45),
                material = Math.floor(total * 0.55),
                design = mianji * 95,
                quality = mianji * 40,
                daikuan = (total * (1 + 0.12) / 36).toFixed(2);

            $('#result').addClass('cur').find('.total').html(total);
            $('.labour').html('<em>' + labour + '元</em>');
            $('.material').html('<em>' + material + '元</em>');
            $('.design').html('<em>' + design + '</em>元');
            $('.quality').html('<em>' + quality + '</em>元');
            $('.daikuan').html(daikuan);
        },
        success: function (result) {
            if (result.code == 1) {
                $("form").each(function () {
                    this.reset();
                });
				//执行成功提交类转化代码(百度信息流)
				//LFL 2018-08-28 14:32:32
				callback_run_baidu_feedads_static();
				
				//提交成功反馈今日头条统计
				//LFL 2018-08-20 18:01:46
				run_toutiao_tj();
				console.log('成功提交！');
            }
            return false;
        }
    })
}


function simpleDesgin(obj) {
    try {
        var username = ($("#username").length > 0) ? ($("#username").val() != '称呼' ? $("#username").val() : '') : '';
        var mobile = ($("#mobile").length > 0) ? $("#mobile").val() : '';
        var position = ($("#c-position").length > 0) ? $("#c-position").val() : '';
        var type = 3;
        var landing_page = ($("#landing_page").length > 0) ? $("#landing_page").val() : '';
    } catch (e) {
    }
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "?controller=ajax/baoming&controllerAction=save",
        data: {
            "type": type,
            "position": position,
            "chenghu": username,
            "phone": mobile,
            "landing_page": landing_page
        },
        beforeSend: function () {
            var reg1 = /^1(3|4|5|7|8)\d{9}$/;
            if ((!username && $("#username").length > 0) || username == '请填写您的名字') {
                $("#username").focus();
                layer.msg('请填写您的名字');
                return false;
            } else if (!reg1.test(mobile) || mobile == '请填写您的联系电话') {
                $("#mobile").focus();
                layer.msg('请填写您的联系电话');
                return false;
            }
            $(obj).find('.form-btn').attr('disabled', 'disabled');
        },
        success: function (result) {
            layer.msg(result.msg);
            if (result.code == 1) {
                $(obj).each(function () {
                    this.reset();
                });
            }
            $(obj).find('.form-btn').removeAttr('disabled');
			
			//执行成功提交类转化代码(百度信息流)
			//LFL 2018-08-28 14:32:32
			callback_run_baidu_feedads_static();
			
			//提交成功反馈今日头条统计
			//LFL 2018-08-20 18:01:46
			run_toutiao_tj();
			console.log('成功提交！');
            return false;
        }
    })
}


//推广页面
function calculateTG(obj) {

    try {
        var province = ($("#province").length > 0) ? $("#province").val() : '';
        var city = ($("#city").length > 0) ? $("#city").val() : '';
        var mianji = ($("#mianji").length > 0) ? ($("#mianji").val() != '面积' ? $("#mianji").val() : '') : '';
        var phone = ($("#phone").length > 0) ? $("#phone").val() : '';
        var position = ($("#c-position").length > 0) ? $("#c-position").val() : '';
        var type = ($("#c-type").length > 0) ? $("#c-type").val() : '';
        var landing_page = ($("#landing_page").length > 0) ? $("#landing_page").val() : '';
    } catch (e) {
    }
    $.ajax({
        type: "POST",
        url: "?controller=ajax/baoming&controllerAction=save",
        data: {
            "type": type,
            "phone": phone,
            "province": province,
            "city": city,
            "mianji": mianji,
            "position": position,
            "landing_page": landing_page
        },
        dataType: "json",
        beforeSend: function () {
            var reg1 = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
            if ((!province && $("#province").length > 0) || province == '请选择省/市') {
                $("#province").focus();
                layer.msg('请选择省/市');
                return false;
            } else if ((!city && $("#city").length > 0) || city == '请选择市/地区') {
                $("#city").focus();
                layer.msg('请选择市/地区');
                return false;
            } else if ((!mianji && $("#mianji").length > 0) || mianji == '请填写房屋面积') {
                $("#mianji").focus();
                layer.msg('请填写房屋面积');
                return false;
            }
            else if (!reg1.test(phone) || phone == '请填写您的联系电话') {
                $("#phone").focus();
                layer.msg('请填写您的联系电话');
                return false;
            }

            var total = Math.floor(mianji / 0.75 * 420),
                labour = Math.floor(total * 0.44),
                material = Math.floor(total * 0.56),
                design = mianji * 80,
                quality = mianji * 50,
                array = String(total).split('').reverse(),
                str = '';  //获取价格数组的倒排序
                $('.m-cal .val').html('');
                for (var i in array) {
                    str = '<img class="num-1" src="/assets/images/cal/' + array[i] + '.png">';
                    $('.m-cal .val').append(str);
                }

                $('.m-cal .num').removeClass('num-bg');
                $('.labour').text(labour + '元');
                $('.material').text(material + '元');
                $('.design').text(design + '元');
                $('.quality').text(quality + '元');
                var info = '您家新房装修约为 ' + total + '元,费用含主材,含设计,含人工,含管理费等;稍后装修客服将回电,为您提供免费咨询服务';
                $('.m-cal').addClass('caled');
        },
        success: function (res) {
            if (res.code == 1) {
                layer.msg('短信发送成功，稍后装修管家将回电您，免费提供装修咨询服务');
				//执行成功提交类转化代码(百度信息流)
				//LFL 2018-08-28 14:32:32
				callback_run_baidu_feedads_static();
				//提交成功反馈今日头条统计
				//LFL 2018-08-20 18:01:46
				run_toutiao_tj();
				console.log('成功提交！');
            } else {
                layer.msg(res.msg);
            }
          //  $(btn).removeAttr('disabled');
        }
    })
}

//推广页面
function calculateTGNew(obj) {
    try {
        var province = ($("#province").length > 0) ? $("#province").val() : '';
        var city = ($("#city").length > 0) ? $("#city").val() : '';
        var mianji = ($("#mianji").length > 0) ? ($("#mianji").val() != '面积' ? $("#mianji").val() : '') : '';
        var phone = ($("#phone").length > 0) ? $("#phone").val() : '';
        var position = ($("#c-position").length > 0) ? $("#c-position").val() : '';
        var type = ($("#c-type").length > 0) ? $("#c-type").val() : '';
        var landing_page = ($("#landing_page").length > 0) ? $("#landing_page").val() : '';
        var hxxq =$("#housty")[0].name;
        var fwlx=$("#fwlx").val();
    } catch (e) {
    }
    $.ajax({
        type: "POST",
        url: "?controller=ajax/baomingNew&controllerAction=save",
        data: {
            "hxxq": hxxq,
            "fwlx": fwlx,
            "type": type,
            "phone": phone,
            "province": province,
            "city": city,
            "mianji": mianji,
            "position": position,
            "landing_page": landing_page
        },
        dataType: "json",
        beforeSend: function () {
            var reg1 = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
            if ((!province && $("#province").length > 0) || province == '请选择省/市') {
                $("#province").focus();
                layer.msg('请选择省/市');
                return false;
            } else if ((!city && $("#city").length > 0) || city == '请选择市/地区') {
                $("#city").focus();
                layer.msg('请选择市/地区');
                return false;
            } else if ((!mianji && $("#mianji").length > 0) || mianji == '请填写房屋面积') {
                $("#mianji").focus();
                layer.msg('请填写房屋面积');
                return false;
            }
            else if (!reg1.test(phone) || phone == '请填写您的联系电话') {
                $("#phone").focus();
                layer.msg('请填写您的联系电话');
                return false;
            }
        },
        success: function (res) {
            if (res.code == 1) {
                layer.msg('短信发送成功，稍后装修管家将回电您，免费提供装修咨询服务');
                //执行成功提交类转化代码(百度信息流)
                //LFL 2018-08-28 14:32:32
                callback_run_baidu_feedads_static();
                //提交成功反馈GDT统计  xuejs 2018-09-12 9:38 Edit
                run_gdt_ad();
                //提交成功反馈今日头条统计  xuejs 2018-09-12 9:38 Edit
                run_toutiao_tj();
                //跳转到报价结果页面
                if (res.href.length>0)
                {
                    setTimeout(function () {
                        window.location.href=res.href;
                    },3000);
                }
            } else {
                layer.msg(res.msg);
            }
          //  $(btn).removeAttr('disabled');
        }
    })
}

